<?php

use yii\db\Migration;

class m170301_072452_alter_goods extends Migration
{

    private function createDbs(){
        $dbs = [];
        $dbs_info =\Yii::$app->params['db'];
        foreach($dbs_info as $k=>$v){
            $dbs[$k] = \Yii::createObject($v);
        }
        return $dbs;
    }


    // Use safeUp/safeDown to run migration code within a transaction
    public function safeUp()
    {
        $dbs = $this->createDbs();
        foreach($dbs as $v) {
            $this->db = $v;
            $this->addColumn('{{%goods}}', 'is_booking',  $this->smallInteger(4).' default 1 comment \'是否可预约（1 是 0 否）\'');
        }
    }

    public function safeDown()
    {
        $dbs = $this->createDbs();
        foreach($dbs as $v) {
            $this->db = $v;
            $this->dropColumn('{{%goods}}', 'is_booking');
        }
    }

}
